﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using OpenGado.DATA.Entities;
using OpenGado.Business;
using OpenGado.DATA;

namespace OpenGado.Win
{
    public partial class frmCategory : Form
    {

        public delegate void UpdateCategoriesHandler();

        public  UpdateCategoriesHandler CategoriesUpdated;

        Categories ct;

        public frmCategory()
        {
            InitializeComponent();
        }

        public frmCategory(int categoryId)
        {
            InitializeComponent();

            ct = CategoryDataControl.Instance.GetCategoryById(categoryId);
            txtCategory.Text =  ct.CategoryName;


        }

        private void btnCategory_Click(object sender, EventArgs e)
        {
            SaveCategory();
            CategoriesUpdated();

        }

        private void SaveCategory()
        {
            if (ct !=null)
            {
                ct.CategoryName = txtCategory.Text;
                CategoryDataControl.Instance.Save(ct);
            }
            else
            {
                Categories cat = new Categories();
                cat.CategoryName = txtCategory.Text;

                CategoryDataControl.Instance.Save(cat);
            }
            
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }




    }
}
